package cn.share.life.common.sensitiveword.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopefound.common.core.constant.Constants;
import com.hopefound.common.core.domain.R;
import com.hopefound.common.core.utils.StringUtils;
import com.hopefound.common.log.annotation.Log;
import com.hopefound.common.log.enums.BusinessType;
import com.hopefound.common.security.annotation.RequiresPermissions;
import com.hopefound.system.domain.SensitiveWordsType;
import com.hopefound.system.service.SensitiveWordsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 敏感词类型(SensitiveWordsType)表控制层
 *
 * @author cxj
 * @since 2025-02-19 10:59:36
 */
@Slf4j
@Api(value = "敏感词类型", tags = "敏感词")
@RestController
@RequestMapping("/sensitiveWordsType")
public class SensitiveWordsTypeController {
    /**
     * 服务对象
     */
    @Autowired
    private SensitiveWordsTypeService sensitiveWordsTypeService;


    /**
     * 分页查询所有数据
     *
     * @param sensitiveWordsType 查询实体
     * @return 所有数据
     */
    @RequiresPermissions("system:sensitiveWordsType:query")
    @ApiOperation("敏感词类型-分页查询所有数据")
    @GetMapping("/pageList")
    public R pageList(SensitiveWordsType sensitiveWordsType
            , @RequestParam(defaultValue = "1") Integer pageNum
            , @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<SensitiveWordsType> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SensitiveWordsType> wrapper = new LambdaQueryWrapper<SensitiveWordsType>()
                .like(StringUtils.isNotEmpty(sensitiveWordsType.getName()), SensitiveWordsType::getName, sensitiveWordsType.getName())
                .orderByDesc(SensitiveWordsType::getCreateTime);
        return R.ok(sensitiveWordsTypeService.page(page, wrapper));
    }

    @ApiOperation("敏感词类型-查询所有数据")
    @GetMapping("/selectList")
    public R selectList(SensitiveWordsType sensitiveWordsType) {
        LambdaQueryWrapper<SensitiveWordsType> wrapper = new LambdaQueryWrapper<SensitiveWordsType>()
                .like(StringUtils.isNotEmpty(sensitiveWordsType.getName()), SensitiveWordsType::getName, sensitiveWordsType.getName())
                .orderByDesc(SensitiveWordsType::getCreateTime);
        return R.ok(sensitiveWordsTypeService.list(wrapper));
    }

    /**
     * 新增数据
     *
     * @param sensitiveWordsType 实体对象
     * @return 新增结果
     */
    @RequiresPermissions("system:sensitiveWordsType:add")
    @ApiOperation("敏感词类型-新增数据")
    @PostMapping("/insert")
    @Log(title = "敏感词类型", businessType = BusinessType.INSERT, systemCode = Constants.BUSINESS_PLATFORM)
    public R insert(@RequestBody SensitiveWordsType sensitiveWordsType) {
        return R.ok(this.sensitiveWordsTypeService.save(sensitiveWordsType));
    }

    /**
     * 修改数据
     *
     * @param sensitiveWordsType 实体对象
     * @return 修改结果
     */
    @RequiresPermissions("system:sensitiveWordsType:edit")
    @ApiOperation("敏感词类型-修改数据")
    @PostMapping("/update")
    @Log(title = "敏感词类型", businessType = BusinessType.UPDATE, systemCode = Constants.BUSINESS_PLATFORM)
    public R update(@RequestBody SensitiveWordsType sensitiveWordsType) {
        return R.ok(this.sensitiveWordsTypeService.updateById(sensitiveWordsType));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @RequiresPermissions("system:sensitiveWordsType:remove")
    @ApiOperation("敏感词类型-删除数据")
    @DeleteMapping
    @Log(title = "敏感词类型", businessType = BusinessType.DELETE, systemCode = Constants.BUSINESS_PLATFORM)
    public R delete(@RequestParam("idList") List<String> idList) {
        return R.ok(this.sensitiveWordsTypeService.removeByIds(idList));
    }
}
